<template>
  <v-chart className="chart" :option="option" autoresize/>
</template>

<script>
import {use} from 'echarts/core';
import {CanvasRenderer} from 'echarts/renderers';
import {PieChart} from 'echarts/charts';
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
} from 'echarts/components';
import VChart, {THEME_KEY} from 'vue-echarts';
import {ref, defineComponent} from 'vue';
import piedata from '../assets/piedata.json'

use([
  CanvasRenderer,
  PieChart,
  TitleComponent,
  TooltipComponent,
  LegendComponent,
]);

export default defineComponent({
  name: 'PieChart',
  components: {
    VChart,
  },
  data:{

  },
  provide: {
    [THEME_KEY]: 'white',
  },
  setup() {
    const option = ref({
      title: {
        text: '销量占比',
        left: 'center',
      },
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)',
      },
      legend: {
        orient: 'vertical',
        left: 'left',
        itemWidth: 25,
        itemHeight: 20,
        data: ['SUV', '轿车', 'MPV'],
      },
      series: [
        {
          name: '销量占比',
          type: 'pie',
          radius: '70%',
          center: ['50%', '60%'],
          data: [
            {value: 9300, name: 'SUV'},
            {value: 10439, name: '轿车'},
            {value: 743, name: 'MPV'}
          ],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
            },
          },
        },
      ],
    });

    return {option};
  },
});
</script>

<style scoped>
.chart {
  height: 100vh;
}
</style>
